int cmp(int* x, int* y)
{
    return *x - *y;
}

int specialArray(int* nums, int numsSize) {
    qsort(nums, numsSize, sizeof(int), cmp);
    int n = 0;
    for (int i = 1; i <= numsSize; i++)
    {
        n = 0;
        for (int j = 0; j < numsSize; j++)
        {
            if (nums[j] >= i)
            {
                n++;
            }
        }
        if (n == i)
            return i;
    }
    return -1;
}